﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Wms_ReciveOrderInfo.aspx.cs" Inherits="JYH.Web.MES.WMS.UI.Wms_ReciveOrderInfo" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>

     

    <script type="text/javascript" >


        let res = {};
        async function Translation()
        {
            if (res != null)
            {
                if (res.PageTitile != null)
                {
                    document.title = res.PageTitile;


                    $('#BtnSearch').linkbutton({
                        text: res.BtnSearch
                    });
                    $('#BtnAddNew').linkbutton({
                        text: res.BtnAddNew
                    });
                    $('#BtnCheck').linkbutton({
                        text: res.BtnCheck
                    });
                    $('#BtnDelete').linkbutton({
                        text: res.BtnDelete
                    });
                    $('#BtnSync').linkbutton({
                        text: res.Synchronous
                    });
                    $('#BtnReturn').linkbutton({
                        text: res.BtnReturn
                    });
                    $('#txtPartnerNO').textbox({
                        prompt: res.VendorNO

                    });
                    $('#txtReciveOrderNO').textbox({
                        prompt: res.ReciveOrderNO
                        //lable: res.ReciveOrderNO
                    });
                    $('#BeginTime').datebox({
                        prompt: res.BeginTime
                        //lable: res.ReciveOrderNO
                    });
                    $('#EndTime').datebox({
                        prompt: res.EndTime
                        //lable: res.ReciveOrderNO
                    });
                    $('#tt').datagrid('options').columns[0][1].title = res.Opt;
                    $('#tt').datagrid('options').columns[0][2].title = res.RStateName;
                    $('#tt').datagrid('options').columns[0][3].title = res.ReciveOrderNO;
                    $('#tt').datagrid('options').columns[0][4].title = res.ReciveDate;
                    $('#tt').datagrid('options').columns[0][5].title = res.VendorNO;
                    $('#tt').datagrid('options').columns[0][6].title = res.VendorName;
                    $('#tt').datagrid('options').columns[0][7].title = res.PartnerOrderNO;
                    $('#tt').datagrid('options').columns[0][8].title = res.CreateTime;
                    $('#tt').datagrid('options').columns[0][9].title = res.CreateUser;
                    $('#tt').datagrid('options').columns[0][10].title = res.ApproveDate;
                    $('#tt').datagrid('options').columns[0][11].title = res.ApproveUser;
                    $('#tt').datagrid('options').title = res.RCOrderList;
                    $('#tt').datagrid('resize');
                    $('#tt').datagrid(); // 重新初始化
                   // $('#tt').datagrid('load'); // 加载数据
                }
            }
        }
        async function TranslationPage() {

            try {
                var lang = {
                    PageName: 'ReciveOrder',
                    LanguageNO: navigator.language
                };

                var url = "/api/SYS/GetPageLanguage";

                // var element = document.getElementById("Literal1");

                let c = await $.ajax({
                    url: url, // 替换为你的API或服务器端点
                    type: 'POST', // 或者 'POST'，取决于你的请求类型
                    data: lang,
                    contentType: "application/x-www-form-urlencoded; charset=UTF-8",
                    success: function (data) {
                        console.log(JSON.stringify(data));
                        // 假设你需要在请求成功后显示元素
                        if (data.Code == 200) {

                            res = data.Items[0];
                            console.log(JSON.stringify(res));
                            if (res != null) {

                        
                                Translation();
                                


                                // document.querySelector('input[type="qBarcodeNO"]').setAttribute('data-options', 'Input Barcode NO');;

                            }
                        }
                        if (data.Code == 500) {

                            console.log(JSON.stringify(data));
                            Notice(data.Message);

                        }

                    },
                    error: function (xhr, status, error) {
                        // 错误处理
                    }
                });



            } catch (error) { }
            //  console.error('Request error:', error);

        };

        $(document).ready(function () {
            TranslationPage();
        }
        );
        
        $(function () {
            $('#tt').datagrid({
                loadMsg: "正在接收数据...",
                iconCls: 'icon-reload',
                url: '',
                idField: 'ReciveOrderID',
                autoRowHeight: false,
                fitColumns: false,
                scrollbarSize: 0,
                pageSize: 20,
                sortable: true,
                striped: false ,      //隔行变色
                singleSelect: false, //是否单选
                pagination: true,   //分页控件  
                rownumbers: true,
                columns: [[
                    { field: 'ReciveOrderID', checkbox: true },
                    { field: 'RState', hidden: true },
                    { field: 'Opt', title: '操作', width: 170, align: 'center', formatter: ColumnOpt },
                    { field: 'RStateName', title: '记录状态', width: 80 },
                    { field: 'ReciveOrderNO', title: '收料单号', width: 140 },
                    { field: 'ReciveDate', title: '收料日期', width: 140 },
                    { field: 'PartnerNO', title: '供应商编号', width: 80 },
                    { field: 'PartnerName', title: '供应商名称' },
                    { field: 'PatnerOrderNO', title: '供应商单号', width: 140 },
                    { field: 'CreateTime', title: '制单日期', width: 140, sortable: true },
                    { field: 'CreateUser', title: '创建人员', width: 100 },
                    { field: 'ApproveDate', title: '审核日期', width: 140, sortable: true },
                    { field: 'ApproveUser', title: '审核人员', width: 100 },
                    { field: 'RState', hidden: true }
                ]],
                rowStyler: function (index, row) {
                    if (row.RState === '1') {
                        // 审核状态（RState=1）：浅蓝色背景 + 深蓝色文字（适用于一般审核状态）
                        return 'background-color:#E3F2FD; color:#0D47A1;';
                    } else if (row.RState === '2') {
                        return 'background-color:#C8E6C9;'; //绿色背景
                    }
                },
                onLoadSuccess: function (data) {
                    
                    $('#tt').datagrid("fillRows");
                    $('#tt').datagrid('resize');
                },
              
                onSortColumn: function (sort, order) {
                    $("#hSort").val(sort);
                    $("#hOrder").val(order);
                }
            });
            $(window).resize(function () {
                $('#tt').datagrid('resize');
            });
            $(".listmore").click(function () {
                $(".flistdis").toggle();
            });
        })
        function IndexOpen(rows) {
            OpenWindow("采购收料单维护", "WMS/UI/WmsProductInStockView.aspx", 1200, 650, function () {
                loadLocal();
            });
        }
        //查询
        function loadLocal() {
            var ReciveOrderNO = $("#txtReciveOrderNO").val();
            var PartnerNO = $("#txtPartnerNO").val();
            var BeginTime = $("#BeginTime").val();
            var EndTime = $("#EndTime").val();
            //排序字段
            var sort = $("#hSort").val();
            var order = $("#hOrder").val();
            $("#tt").datagrid({
                url: '/api/WMS/QueryWmsReciveOrderInfo',
                method: 'Get',
                queryParams: {
                    ReciveOrderNO: ReciveOrderNO,
                    PartnerNO: PartnerNO,
                    BeginTime: BeginTime,
                    EndTime: EndTime,
                    sort: sort,
                    order: order
                },
                loadFilter: function (data) {
                    return JSON.parse(data);
                }
            });
            $('#tt').datagrid('clearSelections');
        }

        //删除
        function Delet() {
            var rows = $('#tt').datagrid('getSelections');
            if (rows.length < 1) {
                Alert("请选择后再删除！");
                return false;
            }
            for (var i = 0; i < rows.length; i++) {
                if (rows[i].RState != "0") {
                    Alert("单据:" + rows[i].ReciveOrderNO + "不在新建状态,无法删除,请立即反审！");
                    return false;
                }
            }
            Confirm("确定要删除" + rows.Length + "个收料单吗？", function () {
                var MateialInfo = fnSelectList('tt', rows);
                var url = '/api/WMS/DeleteWmsReciveOrderInfo';
                DataService.PostJson(url, MateialInfo, function (error, response) {
                    if (error) {
                        Notice("删除成功!");
                    } else {
                        Alert("删除失败!");
                    }
                    loadLocal();
                })

            });
        }

        //审核
        function Check() {
            var rows = $('#tt').datagrid('getSelections');

            if (rows.Length<1) {
                Alert("请选择后再审核！");
                return false;
            }
            for (var i = 0; i < rows.length; i++) {
                if (rows[i].RState != "0") {
                    Alert("单据:" + rows[i].ReciveOrderNO + "不在新建状态,无法审核！");
                    return false;
                }
            }
            Confirm("确定要审核吗？", function () {
                var MateialInfo = fnSelectList('tt', rows);
                var url = '/api/WMS/CheckWmsReciveOrderInfo';
                DataService.PostJson(url, MateialInfo, function (error, response) {
                    if (error) {
                        Notice("审核成功!");
                    } else {
                        Alert("审核失败!");
                    }
                    loadLocal();
                })

            });
        }
        //反审核
        function UpCheck() {
            var rows = $('#tt').datagrid('getSelections');
            if (rows.Length < 1) {
                Alert("请选择后再反审核！");
                return false;
            }
            for (var i = 0; i < rows.length; i++) {
                if (rows[i].RState != "1") {
                    Alert("单据:" + rows[i].ReciveOrderNO + "不在审核状态,无法反审！");
                    return false;
                }
            }
            Confirm("确定要反审核吗？", function () {
                var MateialInfo = fnSelectList('tt', rows);
                var url = '/api/WMS/UpCheckWmsReciveOrderInfo';
                DataService.PostJson(url, MateialInfo, function (error, response) {
                    if (error) {
                        Notice("操作成功!");
                    } else {
                        Alert("操作失败!" + response);
                    }
                    loadLocal();
                })

            });
        }
       
        function myformatter(date) {
            var y = date.getFullYear();
            var m = date.getMonth() + 1;
            var d = date.getDate();
            return y + '-' + (m < 10 ? ('0' + m) : m) + '-' + (d < 10 ? ('0' + d) : d);
        }
        function myparser(s) {
            if (!s) return new Date();
            var ss = (s.split('-'));
            var y = parseInt(ss[0], 10);
            var m = parseInt(ss[1], 10);
            var d = parseInt(ss[2], 10);
            if (!isNaN(y) && !isNaN(m) && !isNaN(d)) {
                return new Date(y, m - 1, d);
            } else {
                return new Date();
            }
        }
        function ColumnOpt(value, row) {
            var temp = JSON.stringify(row);
            return "<a name='lock1' href='#' style='color:#a61c00' data-row='" + encodeURIComponent(temp) + "' onclick='Update(this);'>[Update]</a> &nbsp; | &nbsp;" +
                "<a name='lock2' href='#' style='color:#666666' data-row='" + encodeURIComponent(temp) + "' onclick='View(this);'>[Review]</a>";
        }
        //浏览
        function View(element) {
            var temp = decodeURIComponent(element.getAttribute('data-row'));
            var row = JSON.parse(temp);
            const params = encodeURIComponent(JSON.stringify(row));
            OpenWindow("收料信息维护", "WMS/UI/WmsProductInStockView.aspx?params=" + params + "&view=view", 1200, 650, function () {
                loadLocal();
            });
        }


        function Synch() {
            var SynchName = "SyncReciveOrder";
            OpenWindow("资料同步", "Public/UI/BasSynchronousInfo.aspx?SynchName=" + SynchName , 300, 200, function () {
                loadLocal();
            });
        }
        //修改
        function Update(element) {
            var temp = decodeURIComponent(element.getAttribute('data-row'));
            var row = JSON.parse(temp);
            if (row.RState != "0") {
                Notice("不在新建状态,无法修改！");
                return false;
            }
            const params = encodeURIComponent(JSON.stringify(row));
            OpenWindow("收料信息维护", "WMS/UI/WmsProductInStockView.aspx?params=" + params, 1200, 650, function () {
                loadLocal();
            });
        }

        function Reset()
        {
            var rows = $('#tt').datagrid('getSelections');
            if (rows.length == 1) {
                var ReceiveOrderID = rows[0].ReciveOrderID;
                const viewportWidth = window.innerWidth || document.documentElement.clientWidth;
                const viewportHeight = window.innerHeight || document.documentElement.clientHeight;
                OpenWindow("Receiving Order Info", "WMS/UI/WmsReceiveOrderReset.aspx?ReceiveOrderID=" + ReceiveOrderID, viewportWidth-100, viewportHeight-80, function () {

                });
            }
            else
            {

                Alert("Only Select One Row！");
                return false;
            }
            

        }

  
      
    </script>
</head>
<body>
    <form id="form1" runat="server">
        <%--排序隐藏值--%>
        <asp:HiddenField runat="server" ID="hSort" />
        <asp:HiddenField runat="server" ID="hOrder" />
        <div class="pagebox">
            <div class="cbox">
                <!--工具栏-->
                <div class="easyui-panel" style="padding: 15px; width: 100%;">
                    <div id="tb">
                        <ul class="flist">
                            <li>
                                <input class="easyui-textbox" type="text" id="txtPartnerNO" data-options="prompt:'请输入供应商信息'" style="width: 250px; height: 35px; line-height: 35px;" /></li>
                            <li>
                                <input class="easyui-textbox" type="text" id="txtReciveOrderNO" data-options="prompt:'请输入收料单号'" style="width: 250px; height: 35px; line-height: 35px;" /></li>
                            <li>
                                <input class="easyui-datebox" labelposition="top" id="BeginTime" data-options="prompt:'收料日期',formatter:myformatter,parser:myparser" style="width: 250px; height: 35px;" />
                            </li>
                            <li>
                                <input class="easyui-datebox" labelposition="top" id="EndTime" data-options="prompt:'至',formatter:myformatter,parser:myparser" style="width: 250px; height: 35px;" />
                            </li>
                        </ul>
                        <div>
                            <a href="javascript:void(0)" class="easyui-linkbutton c1" onclick="loadLocal()"  id="BtnSearch" data-options="iconCls:'icon-sousuo',selected:true">查 询</a>
                            <a href="#" class="easyui-linkbutton c4" data-options="iconCls:' icon-bianji'"    id="BtnAddNew" onclick="IndexOpen('')">新 增</a>
                            <a href="#" class="easyui-linkbutton c8" data-options="iconCls:'icon-xiangmu'"     id="BtnCheck" onclick="Check()">审 核</a>
                            <a href="#" class="easyui-linkbutton c6" data-options="iconCls:'icon-Components'"  id="BtnReturn" onclick="UpCheck()">反 审</a>
                            <a href="#" class="easyui-linkbutton c2" data-options="iconCls:'icon-buchongiconsvg13'"  id="BtnDelete" onclick="Delet()">删 除</a>
                            <a href="#" class="easyui-linkbutton c7" data-options="iconCls:'icon-xiangxia'"  id="BtnSync" onclick="Synch()">同步</a>
                            <a href="#" class="easyui-linkbutton c5" data-options="iconCls:'icon-bianji'"    id="BtnReset" onclick="Reset()">Reset</a>
                        </div>

                    </div>
                </div>
            </div>
            <div class="cbox">
                <!--查询结果清单-->
                <table id="tt" title="产品列表">
                </table>
            </div>
        </div>
    </form>
</body>

</html>
